package com.web.action;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.web.model.constant.Constant;
import com.web.service.TConfigService;
import com.web.utils.WebUtil;

@Controller
@RequestMapping
public class IndexAction {

	@Autowired
	private TConfigService tConfigService;

	@RequestMapping(value = "index", method = RequestMethod.GET)
	public String toAddUser() {
		return "home";
	}

	/* 用户协议 */
	@RequestMapping(value = "agreement", method = RequestMethod.GET)
	public String agreement() {
		return "agreement";
	}

	/* 百度页面验证码校验 */
	@RequestMapping(value = "search", method = RequestMethod.POST)
	public ModelAndView toAddUser(HttpServletRequest request,HttpSession session) {
		ModelAndView mv = new ModelAndView();
		try {
			String word = request.getParameter("word");
			if (WebUtil.isEmpty(word)) {
				mv.setViewName("redirect:/index");
				return mv;
			}
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("pwd", word.trim());
			Integer count = tConfigService.selectListCount(map);
			// 查询数据库验证码
			if (count > 0) {
				session.setAttribute(Constant.SESSION_TOKEN, word);
				mv.setViewName("redirect:/select_line");
			} else {
				mv.setViewName("redirect:https://www.baidu.com/s?wd=" + word);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return mv;
	}

	/* 选择路线 */
	@RequestMapping(value = "select_line", method = RequestMethod.GET)
	public String select_line(HttpServletRequest request,HttpSession session) {
		String token = (String) session.getAttribute(
				Constant.SESSION_TOKEN);
		if (WebUtil.isEmpty(token)) {
			return "home";
		} else {
			return "select_line";
		}
	}

	/* 未实现功能 */
	@RequestMapping(value = "wait", method = RequestMethod.GET)
	public String waitJsp() {
		return "wait";
	}
	
	/*重庆时时彩*/
	@RequestMapping(value = "qc_all", method = RequestMethod.GET)
	public String shishicai() {
		return "/cq/cq_all";
	}
	
	/*重庆时时彩第一球*/
	@RequestMapping(value = "one", method = RequestMethod.GET)
	public String one() {
		return "/cq/cq_one";
	}
	
	/*重庆时时彩第二球*/
	@RequestMapping(value = "two", method = RequestMethod.GET)
	public String two() {
		return "/cq/cq_two";
	}
	
	/*重庆时时彩第三球*/
	@RequestMapping(value = "there", method = RequestMethod.GET)
	public String there() {
		return "/cq/cq_there";
	}
	
	/*重庆时时彩第四球*/
	@RequestMapping(value = "four", method = RequestMethod.GET)
	public String four() {
		return "/cq/cq_four";
	}
	
	/*重庆时时彩第五球*/
	@RequestMapping(value = "five", method = RequestMethod.GET)
	public String five() {
		return "/cq/cq_five";
	}
	

}
